﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
	<th:block th:include="include :: header('数据空间')" />
</head>

<body>

            <div class="container-div">
				<div class="row">
					<div class="col-sm-12 search-collapse">
						<form id="form1">
							<div class="select-list">
								<ul>
									<li>
										空间名称：<input type="text" name="spaceName"/>
									</li>
									<li>
										<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('form1', 'bootstrap-table1')"><i class="fa fa-search"></i>&nbsp;搜索</a>
										<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset('form1', 'bootstrap-table1')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
									</li>
								</ul>
							</div>
						</form>
					</div>
					<!--
					<div class="btn-group-sm" id="toolbar1" role="group">
						<a class="btn btn-success" onclick="options1()">
							<i class="fa fa-search"></i> options
						</a>
						<a class="btn btn-success" onclick="$.operate.add()">
							<i class="fa fa-plus"></i> 新增
						</a>
						<a class="btn btn-primary single disabled" onclick="$.operate.edit()">
							<i class="fa fa-edit"></i> 修改
						</a>
						<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
							<i class="fa fa-remove"></i> 删除
						</a>
					</div>
					-->
					<div class="btn-group-sm" id="toolbar" role="group">
						<a class="btn btn-warning" onclick="createSpace()">
							<i class="fa fa-plus"></i> 创建空间
						</a>
					</div>
					<div class="col-xs-12 select-table table-striped">
						<table id="bootstrap-table1"></table>
					</div>
				</div>
			</div>

	<th:block th:include="include :: footer" />
    <script th:inline="javascript">
        //var prefix = "http://127.0.0.1/demo/operate";
        //var datas = [[${@dict.getType('sys_normal_disable')}]];
		
        $(function() {
            var options = {
            	id: "bootstrap-table1",
            	formId: "form1",
            	//toolbar: "toolbar1",
                url: "/hddata/dataSpaceList",
                //createUrl: prefix + "/add",
                removeUrl: "/hddata/removeSpace",
                updateUrl: "/hddata/editSpace/{id}",
				//data:data,
		        modalName: "数据空间",
                columns: [{
                    field: 'id',
                    title: '数据ID',
                    visible: false
                },
                {
                    field: 'spaceName',
                    title: '空间名称'
                },
                {
                    field: 'spacePath',
                    title: '空间路径'
                },
                {
                    field: 'spaceDeviceName',
                    title: '设备名称'
                },
                {
                    field: 'spaceType',
                    title: '空间类型',
                    visible: false,
                    align: 'center',
                    formatter: function(value, row, index) {
                    	if(value == 0){
							return "<span class='badge badge-primary'>独立磁盘</span>";
						}else{
							return "<span class='badge badge-warning'>虚拟磁盘</span>";
						}
                    }
                },
                {
                    field: 'spaceAttribute',
                    title: '空间属性',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	if(value == 0){
							return "<span class='badge badge-primary'>临时空间</span>";
						}else if(value == 1){
							return "<span class='badge badge-success'>永久空间</span>";
						}else{
							return "<span class='badge badge-warning'>用户空间</span>";
						}
                    }
                },
                {
                    field: 'spaceTotalVolume',
                    title: '创建时总容量',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	return value + "GiB";
                    }
                },
                {
                    field: 'spaceFreeVolume',
                    title: '创建时可用容量',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	return value + "GiB";
                    }
                },
                {
                    field: 'belongUserId',
                    title: '所属用户id',
                    visible: false,
                },
                {
                    field: 'belongUserName',
                    title: '所属用户名称'
                },
                {
                    field: 'spaceDeleteFlag',
                    title: '删除标志',
                    visible: false,
                },
                {
                    field: 'spaceStopFlag',
                    title: '空间启用',
		        	align: 'center',
		        	formatter: function (value, row, index) {
		        		return statusTools(row);
		        	}
                },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs" href="###" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>修改</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="###" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
        
		//创建空间
		function createSpace(){
			var options = {
                title: '创建磁盘空间',
                url: "/hddata/createDataSpace",
				width: 1000,
                height: 600,
                callBack: doSubmit3
             };
             $.modal.openOptions(options);
		}
		
		//创建空间回调方法
		function doSubmit3(index, layero){
			var body = $.modal.getChildFrame(index);
			//var hehe = body.find('#form-spaceManage-add').serialize();
			//发送AJAX请求
		   	 $.ajax({
	            url: "/hddata/addDataSpace",
	            data: body.find('#form-spaceManage-add').serialize(),
	            type: "post",
	            success: function(result) {
	            	if (result.code == web_status.SUCCESS) {
	            		$.modal.msg("创建成功!");
	                    $.modal.close(index);
	                } else {
	                	$.modal.msg(result.msg);
	                }
	            }
	        })　　　
			
		}
		
		//修改空间
		function editSpace(){
			//$.modal.open("修改阵列信息", "hd_control_net.html");
			alert("修改");
		}
		
		//删除空间
		function deleteSpace(){
			//$.modal.open("修改阵列信息", "hd_control_net.html");
			alert("删除");
		}		

		
		/* 空间状态显示 */
		function statusTools(row) {
		    if (row.spaceStopFlag == '0') {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
    		}
		}
		
		/* 空间管理-停用 */
		function disable(spaceId) {
			$.modal.confirm("确认要停用空间吗？", function() {
				$.operate.post("/hddata/changeDataSpaceStatus", { "spaceId": spaceId, "stopFlag": "0" });
		    })
		}

		/* 空间管理启用 */
		function enable(spaceId) {
			$.modal.confirm("确认要启用空间吗？", function() {
				$.operate.post("/hddata/changeDataSpaceStatus", { "spaceId": spaceId, "stopFlag": "1" });
		    })
		}
		
    </script>

</body>

</html>